package com.h2.controller;

import com.h2.dao.RoleDao;
import com.h2.entity.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: TongRui乀
 * @Date: 2020-09-09 9:54
 * @description：
 */
@RestController
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleDao roleDao;

    @PostMapping("create")
    public Role create(@RequestBody Role role){

        return this.roleDao.save(role);
    }

    @GetMapping("get/{id}")
    public Role get(@PathVariable Integer id){
        return this.roleDao.getOne(id);
    }

    @GetMapping("del/{id}")
    public String delete(@PathVariable Integer id){
        Role role = new Role();
        role.setId(id);
        this.roleDao.delete(role);
        return "SUCCESS";
    }

}
